﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Windows;
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class DependencyPropertyXmlConfigurationTests
    {
        const string StandardXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit' typeConverter='LengthConverter' ></blah>";
        const string MissingDescriptionXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string EmptyDescriptionXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string MissingSummaryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string EmptySummaryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string MissingRemarksXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' description='My description' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string EmptyRemarksXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='' description='My description' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";

        const string MissingTypeConverterXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string EmptyTypeConverterXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='' provideSetter='false' localizable='true' localizationCategory='Button' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";

        const string EmptyLocalizationCategoryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationCategory='' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string InvalidLocalizationCategoryXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationCategory='blah' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationCategoryLocalizableTypeXml = "<blah name='my name' type='string' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationCategoryNotLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='false' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationCategoryIsLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' localizationModifiability='Inherit' localizationReadability='Inherit'></blah>";

        const string EmptyLocalizationModifiabilityXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationModifiability='Button' localizationModifiability='' localizationReadability='Inherit'></blah>";
        const string InvalidLocalizationModifiabilityXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationModifiability='Button' localizationModifiability='blah' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationModifiabilityLocalizableTypeXml = "<blah name='my name' type='string' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' LocalizationModifiability='Button' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationModifiabilityNotLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='false' LocalizationModifiability='Button' localizationReadability='Inherit'></blah>";
        const string MissingLocalizationModifiabilityIsLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationModifiability='Button' localizationReadability='Inherit'></blah>";

        const string EmptyLocalizationReadabilityXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationReadability='Button' localizationModifiability='Inherit' localizationReadability=''></blah>";
        const string InvalidLocalizationReadabilityXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationReadability='Button' localizationModifiability='Inherit' localizationReadability='blah'></blah>";
        const string MissingLocalizationReadabilityLocalizableTypeXml = "<blah name='my name' type='string' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' LocalizationReadability='Button' localizationModifiability='Inherit' ></blah>";
        const string MissingLocalizationReadabilityNotLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='false' LocalizationReadability='Button' localizationModifiability='Inherit' ></blah>";
        const string MissingLocalizationReadabilityIsLocalizableXml = "<blah name='my name' type='MyType' defaultValue='defaultValue' summary='My summary.' remarks='My remarks.' description='My description' provideSetter='false' localizable='true' LocalizationReadability='Button' localizationModifiability='Inherit' ></blah>";

        [TestMethod]
        public void TestDescription()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My description", config.Description);
        }

        [TestMethod]
        public void TestTypeConverter()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("LengthConverter", config.TypeConverter);
        }

        [TestMethod]
        public void TestLocalizationCategory()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(LocalizationCategory.Button, config.LocalizationCategory);
        }

        [TestMethod]
        public void TestLocalizationModifiability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Modifiability.Inherit, config.LocalizationModifiability);
        }

        [TestMethod]
        public void TestLocalizationReadability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Readability.Inherit, config.LocalizationReadability);
        }

        [TestMethod]
        public void TestRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My remarks.", config.Remarks);
        }

        [TestMethod]
        public void TestSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My summary.", config.Summary);
        }


        [TestMethod]
        public void TestReaderAdvancement()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(StandardXml);

            Assert.IsTrue(xmlReader.IsStartElement());

            var config = new AttachedDependencyPropertyXmlConfiguration(xmlReader);

            Assert.IsFalse(xmlReader.IsStartElement());
        }

        [TestMethod]
        public void TestMissingDescription()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingDescriptionXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("My summary.", config.Description);
        }

        [TestMethod]
        public void TestEmptyDescription()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyDescriptionXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.Description);
        }

        [TestMethod]
        public void TestMissingTypeConverter()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingTypeConverterXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.TypeConverter);
        }

        [TestMethod]
        public void TestEmptyTypeConverter()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyTypeConverterXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.TypeConverter);
        }

        [TestMethod]
        public void TestMissingSummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingSummaryXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(null, config.Summary);
        }

        [TestMethod]
        public void TestEmptySummary()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptySummaryXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.Summary);
        }

        [TestMethod]
        public void TestMissingRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingRemarksXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(null, config.Remarks);
        }

        [TestMethod]
        public void TestEmptyRemarks()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyRemarksXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("", config.Remarks);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestEmptyLocalizationCategory()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyLocalizationCategoryXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationCategory);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestInvalidLocalizationCategory()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(InvalidLocalizationCategoryXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationCategory);
        }

        [TestMethod]
        public void TestMissingLocalizationCategoryLocalizableType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationCategoryLocalizableTypeXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(LocalizationCategory.Text, config.LocalizationCategory);
        }

        [TestMethod]
        public void TestMissingLocalizationCategoryNotLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationCategoryNotLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(LocalizationCategory.None, config.LocalizationCategory);
        }

        [TestMethod]
        public void TestMissingLocalizationCategoryIsLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationCategoryIsLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(LocalizationCategory.Text, config.LocalizationCategory);
        }


        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestEmptyLocalizationModifiability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyLocalizationModifiabilityXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationModifiability);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestInvalidLocalizationModifiability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(InvalidLocalizationModifiabilityXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationModifiability);
        }

        [TestMethod]
        public void TestMissingLocalizationModifiabilityLocalizableType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationModifiabilityLocalizableTypeXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Modifiability.Modifiable, config.LocalizationModifiability);
        }

        [TestMethod]
        public void TestMissingLocalizationModifiabilityNotLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationModifiabilityNotLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Modifiability.Unmodifiable, config.LocalizationModifiability);
        }

        [TestMethod]
        public void TestMissingLocalizationModifiabilityIsLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationModifiabilityIsLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Modifiability.Modifiable, config.LocalizationModifiability);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestEmptyLocalizationReadability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(EmptyLocalizationReadabilityXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationReadability);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void TestInvalidLocalizationReadability()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(InvalidLocalizationReadabilityXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual("blah", config.LocalizationReadability);
        }

        [TestMethod]
        public void TestMissingLocalizationReadabilityLocalizableType()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationReadabilityLocalizableTypeXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Readability.Readable, config.LocalizationReadability);
        }

        [TestMethod]
        public void TestMissingLocalizationReadabilityNotLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationReadabilityNotLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Readability.Unreadable, config.LocalizationReadability);
        }

        [TestMethod]
        public void TestMissingLocalizationReadabilityIsLocalizable()
        {
            var xmlReader = XmlTestHelp.CreateXmlReader(MissingLocalizationReadabilityIsLocalizableXml);
            var config = new DependencyPropertyXmlConfiguration(xmlReader);

            Assert.AreEqual(Readability.Readable, config.LocalizationReadability);
        }

    }
}
